package main

// 子数组的最大平均值
// 平均数最大且长度为k的连续子数组

func findMaxAverage(nums []int, k int) float64 {
	n := len(nums)
	l, r := 0, k-1
	sum := 0
	for i := l; i <= r; i++ {
		sum += nums[i]
	}
	res := sum

	for r < n-1 {
		sum = sum - nums[l] + nums[r+1]
		l = l + 1
		r = r + 1
		res = max(res, sum)
	}
	return float64(res) / float64(k)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
